package demo1;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

class Operation{
    //增加
    //删除
    //查找
    //修改
}
public class JDBC {
    public static void main(String[] args) throws SQLException {
        //1.创建数据源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/user?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setURL("123456");
        //2.建立连接
        Connection connection = dataSource.getConnection();
        //3.用户输入

        //4.构造sql语句
        String sql = "insert into student values(?, ?)";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setInt(1,1);
        statement.setString(2,"a");
        int n = statement.executeUpdate();
        //5.关闭
        statement.close();
        connection.close();

    }
}
